package com.googlecode.yoohoo.xmppcore.utils;

import junit.framework.Assert;

import org.junit.Test;

public class XmlUtilsTest {
	@Test
	public void escape() {
		String unescapedString = "\"bread\" & \"butter\"";
		String escapedString = "&quot;bread&quot; &amp; &quot;butter&quot;";
		
		Assert.assertEquals(escapedString, XmlUtils.escape(unescapedString));
	}
	
	@Test
	public void unescape() {
		String unescapedString = "\"bread\" & \"butter\"";
		String escapedString = "&quot;bread&quot; &amp; &quot;butter&quot;";
		Assert.assertEquals(unescapedString, XmlUtils.unescape(escapedString));
		
		unescapedString = "\"bread\" & \"butter&quot";
		escapedString = "&quot;bread&quot; &amp; &quot;butter&quot";
		Assert.assertEquals(unescapedString, XmlUtils.unescape(escapedString));
		
		unescapedString = "\"bread\" &amppp; \"butter&quot";
		escapedString = "&quot;bread&quot; &amppp; &quot;butter&quot";
		Assert.assertEquals(unescapedString, XmlUtils.unescape(escapedString));
		
		unescapedString = "\"bread\" &amppp; &&&amp&\"butter&quot";
		escapedString = "&quot;bread&quot; &amppp; &&&amp&&quot;butter&quot";
		Assert.assertEquals(unescapedString, XmlUtils.unescape(escapedString));
	}
}
